﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ITProject.Domain;
using System.Web.Mvc;
using ITProject.Domain.Entities;
using System.ComponentModel.DataAnnotations;

namespace ITProject.WebUI.Models.ProjectAdmin
{
    public class ProjectAdminCreateReleaseViewModel
    {
        [Required(ErrorMessage="Nazwa wersji jest wymagana")]
        [MinLength(4,ErrorMessage="Nazwa wersji musi posiadać co najmniej 4 znaki")]
        [Display(Name="Nazwa")]
        public string Name { get; set; }
        [Display(Name="Opis wersji")]
        public string Description { get; set; }
        [DataType(DataType.Date)]
        //[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
        [Display(Name ="Planowana data wydania wersji")]
        [Required(ErrorMessage="Podanie planowanej daty wydania jest wymagane")]
        public DateTime PlannedEndDate { get; set; }
        [Required(ErrorMessage="Musisz podać status wersji")]
        [Display(Name="Status wersji")]
        public string ReturnStatus { get; set; }

        //ustawiane przez kontroler
        public string ProjectName { get; set; }

        public static List<SelectListItem> StatusList;

        static ProjectAdminCreateReleaseViewModel()
        {
            StatusList = new List<SelectListItem>();
            StatusList.Add(new SelectListItem { Text = StatusName.Active });
            StatusList.Add(new SelectListItem { Text = StatusName.Planned });
            StatusList.Add(new SelectListItem { Text = StatusName.Done });
            StatusList.Add(new SelectListItem { Text = StatusName.Tested });
            StatusList.Add(new SelectListItem { Text = StatusName.Accepted });
        }

        public static Release Convert(ProjectAdminCreateReleaseViewModel vm, int projectId)
        {
            Release release = new Release();
            release.Name = vm.Name;
            release.Description = vm.Description;
            release.PlannedEndDate = vm.PlannedEndDate;
            release.Status = (byte)StatusName.ConvertFromString(vm.ReturnStatus);
            release.ProjectId = projectId;
            return release;
        }
    }
}